home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / program / nwlib15.zip / DEMO.ZIP / LIST.PAS < prev    next >
Pascal/Delphi Source File  |  1996-06-01  |  22KB  |  630 lines

  1. {This unit provides a generic listbox control and buttons, whose
  2. events can be assigned to procedures stored within the body of THIS
  3. unit, not the calling unit.  Other units can assign these internal
  4. procedures to the available buttons, events, etc. programmatically.
  5.  
  6. The event-handling procedures contained in this unit could certainly
  7. be placed inside the calling unit for good organizational practices.
  8. They are placed in this unit simply to increase clarity of the
  9. NWLib demo program by reducing interface code. }
  10.  
  11. unit List;
  12.  
  13. interface
  14.  
  15. uses
  16.     sysUtils,
  17.     WinTypes,
  18.     WinProcs,
  19.     Classes,
  20.     Graphics,
  21.     Forms,
  22.     Controls,
  23.     Buttons,
  24.     StdCtrls,
  25.     ExtCtrls,
  26.     Grids,
  27.     dialogs,
  28.     Nwtools,
  29.     Nwlib,
  30.     NwProp, 
  31.     NWprint;
  32.  
  33. type
  34.   TwinList = class(TForm)
  35.     Panel1: TPanel;
  36.     buttonPanel: TPanel;
  37.     listGrid: TStringGrid;
  38.     Button1: TButton;
  39.     Button2: TButton;
  40.     Button3: TButton;
  41.     Button4: TButton;
  42.     NWLib1: TNWLib;
  43.     NWTools1: TNWTools;
  44.     NWProp1: TNWProp;
  45.     NWPrint1: TNWPrint;
  46.     procedure FormPaint(Sender: TObject);
  47.     procedure FormShow(Sender: TObject);
  48.   private
  49.     { Private declarations }
  50.   public
  51.     { Public declarations }
  52.     inObjectName : string ;
  53.     inServer     : TNWConnHandle ;
  54.     inQueue      : TObjID ;
  55.     procedure onPrintJobsShow(sender : TObject) ;
  56.     procedure onPropertiesShow(sender : TObject)  ;
  57.     procedure onGroupShow(sender : TObject)  ;
  58.     procedure onRightsShow(sender : TObject)  ;
  59.     procedure onMemberShow(sender : TObject)  ;
  60.     procedure UserAddGroup(sender : TObject) ;
  61.     procedure groupAddUser(sender : TObject) ;
  62.     procedure userDelFromGroup(sender  : TObject) ;
  63.     procedure groupDelUser(sender  : TObject) ;
  64.     procedure objSeeObjectInfo(sender  : TObject) ;
  65.     procedure showPropertyInfo(sender  : TObject) ;
  66.     procedure createNewProperty(sender : TObject) ;
  67.     procedure deleteObjProperty(sender : TObject) ;
  68.     procedure addNewRight(sender : TObject) ;
  69.     procedure deleteRight(sender : TObject) ;
  70.     procedure editRight(sender : TObject) ;
  71.     procedure queueJobInfo(sender : TObject) ;
  72.     procedure queueJobDelete(sender : TObject) ;
  73.   end;
  74.  
  75. var
  76.   winList: TwinList;
  77.  
  78. implementation
  79.  
  80. {$R *.DFM}
  81.  
  82. uses
  83.   trustee ;
  84.  
  85. procedure TwinList.FormShow(Sender: TObject);
  86.   {set grid's lineheight to current font (nwtools.pas)}
  87.   begin
  88.     autoGridLineHeight(listGrid) ;
  89.   end;
  90.  
  91. procedure TwinList.FormPaint(Sender: TObject);
  92.   {enable/disable buttons}
  93.   begin
  94.     button1.enabled := (listGrid.rowCount > 1) ;
  95.     button2.enabled :=  button1.enabled ;
  96.     button3.enabled :=  button1.enabled ;
  97.   end;
  98.  
  99. {********************* formShow methods **********************}
  100.  
  101. procedure TWinList.onPrintJobsShow(sender : TObject) ;
  102.   { used when a print queue is double-clicked to show jobs}
  103.   var
  104.     ncursor  : TCursor ;
  105.     tempList : TStringList ;
  106.     nLoop    : word ;
  107.   begin
  108.     ncursor       := screen.cursor ;
  109.     screen.cursor := crHourglass ;
  110.     tempList      := TStringList.create ;
  111.     caption       := 'Print Queue Contents' ;
  112.     { Edit listGrid's Button Properties }
  113.     { Loads onClick events, edits captions }
  114.     button1.caption := '&Delete'   ;
  115.     button2.caption := '&Info'     ;
  116.     button3.caption := '&Refresh'  ;
  117.     button4.caption := '&Quit'     ;
  118.     button1.onClick := queueJobDelete ;
  119.     button2.onClick := queueJobInfo ;
  120.     button3.onClick := onPrintJobsShow ;
  121.     button4.modalResult := mrCancel ;
  122.  
  123.     {get queue jobs and fill up the grid}
  124.     if (not getQueueJobList(inServer,
  125.                             getObjName(inServer,inQueue),
  126.                             tempList)) then
  127.       exit ;
  128.     listGrid.rowCount    := (tempList.count+1) ;
  129.     listGrid.cells[0,0]  := 'Owner        Status     Description'  ;
  130.     listGrid.onDblClick  := button3.onClick    ;
  131.     for nLoop := 1 to tempList.count do begin
  132.       listGrid.cells[0,nloop] := tempList[nloop-1] ;
  133.       listGrid.cells[1,nloop] := intToStr(TNWQueueJobID(tempList.objects[nloop-1])) ;
  134.     end;
  135.     if (listGrid.rowCount > 1) then
  136.       begin
  137.         listGrid.fixedRows := 1 ;
  138.         listGrid.row := 1 ;
  139.       end;
  140.     tempList.free ;
  141.     screen.cursor := ncursor ;
  142.   end;
  143.  
  144.  
  145. procedure TWinList.onGroupShow(sender : TObject)  ;
  146.   { used when objEdit's 'My Groups' button is selected }
  147.   var
  148.     ncursor  : TCursor ;
  149.     tempList : TStringList ;
  150.     nLoop    : word ;
  151.   begin
  152.     ncursor       := screen.cursor ;
  153.     screen.cursor := crHourglass ;
  154.     tempList      := TStringList.create ;
  155.     caption       := inObjectName + ': Groups I''m In' ;
  156.     { Edit listGrid's Button Properties }
  157.     { Loads onClick events, edits captions }
  158.     button1.caption := '&Add'     ;
  159.     button2.caption := '&Delete'  ;
  160.     button3.caption := '&Info'    ;
  161.     button4.caption := '&Quit'    ;
  162.     button1.onClick := userAddGroup     ;
  163.     button2.onClick := userDelFromGroup ;
  164.     button3.onClick := objSeeObjectInfo ;
  165.     button4.modalResult := mrCancel ;
  166.     { Edit and Fill Up the listGrid }
  167.     tempList := getMyGroups(inServer,
  168.                             inObjectName) ;
  169.     listGrid.rowCount     := (tempList.count+1) ;
  170.     listGrid.cells[0,0]   := 'Group Name'       ;
  171.     listGrid.onDblClick   := button3.onClick    ;
  172.     for nLoop := 1 to tempList.count do
  173.       listGrid.cells[0,nloop] := tempList[nloop-1] ;
  174.     if (listGrid.rowCount > 1) then
  175.       begin
  176.         listGrid.fixedRows := 1 ;
  177.         listGrid.row := 1 ;
  178.       end;
  179.     tempList.free ;
  180.     screen.cursor := ncursor ;
  181.   end;
  182.  
  183. procedure TWinList.onMemberShow(sender : TObject)  ;
  184.   { used when objEdit's or winList's 'Members' button is selected }
  185.   var
  186.     ncursor  : TCursor ;
  187.     tempList : TStringList ;
  188.     nLoop    : word ;
  189.   begin
  190.     ncursor       := screen.cursor ;
  191.     screen.cursor := crHourglass ;
  192.     tempList      := TStringList.create ;
  193.     caption       := inObjectName + ': Group Members' ;
  194.     { Edit listGrid's Button Properties }
  195.     { Loads onClick events, edits captions }
  196.     button1.caption := '&Add'     ;
  197.     button2.caption := '&Delete'  ;
  198.     button3.caption := '&Info'    ;
  199.     button4.caption := '&Quit'    ;
  200.     button1.onClick := groupAddUser ;
  201.     button2.onClick := groupDelUser ;
  202.     button3.onClick := objSeeObjectInfo ;
  203.     button4.modalResult := mrCancel ;
  204.     { Edit and Fill Up the listGrid }
  205.     tempList := GetMemberList(inServer,
  206.                               inObjectName,
  207.                               True) ;
  208.     listGrid.rowCount     := tempList.count+1 ;
  209.     listGrid.cells[0,0]   := 'User ID'        ;
  210.     listGrid.onDblClick   := button3.onClick  ;
  211.     for nLoop := 1 to tempList.count do
  212.       listGrid.cells[0,nloop] := tempList[nloop-1] ;
  213.     if (listGrid.rowCount > 1) then
  214.       begin
  215.         listGrid.fixedRows := 1 ;
  216.         listGrid.row := 1 ;
  217.       end;
  218.     screen.cursor := ncursor ;
  219.     tempList.free ;
  220.   end;
  221.  
  222.  
  223. procedure TWinList.onPropertiesShow(sender : TObject)  ;
  224.   { used when objEdit's 'Properties' button is selected }
  225.   var
  226.     ncursor  : TCursor ;
  227.     tempList : TStringList ;
  228.     nLoop    : word ;
  229.   begin
  230.     ncursor       := screen.cursor ;
  231.     screen.cursor := crHourglass ;
  232.     tempList      := TStringList.create ;
  233.     caption       := inObjectName + ': Valid Properties' ;
  234.     { Edit listGrid's Button Properties }
  235.     { Loads onClick events, edits captions }
  236.     button1.caption := '&Add'     ;
  237.     button2.caption := '&Delete'  ;
  238.     button3.caption := '&Info'    ;
  239.     button4.caption := '&Quit'    ;
  240.     button1.onClick := createNewProperty ;
  241.     button2.onClick := deleteObjProperty ;
  242.     button3.onClick := showPropertyInfo ;
  243.     button4.modalResult := mrCancel ;
  244.     { Edit and Fill Up the listGrid }
  245.     listGrid.rowCount     := tempList.count+1 ;
  246.     listGrid.cells[0,0]   := 'Property Name'     ;
  247.     listGrid.onDblClick   := button3.onClick  ;
  248.     tempList := getPropertyList(inServer,inObjectName,'*') ;
  249.     listGrid.rowCount     := (tempList.count+1) ;
  250.     for nLoop := 1 to tempList.cou